<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>提前结清管理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div class="searchArea">
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="fieldBox">
						<div class="label">融资机构：</div>
						<%-- <div class="field">
							<select name="fncInsId" id="fncInsId" data-value=" ">
								<option value=" " selected="selected">请选择</option>
								<c:forEach items="${fundRasInsNmList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div> --%>
						<div class="field">
                   		 <input name="fncInsId" id="fncInsId" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
		                </div>
		                <div style="display: none">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">融资方案：</div>
						<div class="field">
							<select name="fncScmId" id="fncScmId" data-value=" ">
								<option value=" " selected="selected">请选择</option>
								<c:forEach items="${fncScmNmList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">项目名称：</div>
						<div class="field">
							<input name="fncPrjNm" id="fncPrjNm" type="text" class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">结清状态：</div>
						<div class="field">
							<select name="fncSettleStcd" id="fncSettleStcd" data-value=" ">
								<option value=" " selected="selected">请选择</option>
								<option value="7" >未结清</option>
								<option value="9" >结清中</option>
								<option value="13" >已结清</option>
							</select>
						</div>
					</div>
					<div class="clearFix"></div>
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round" onclick="clearBtn();">清空</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide" />
					</div>
				</div>
			</form>
		</div>
	</div>
	<div id="ligergrid1" class="sq-grid"></div>
</body>
<script type="text/javascript">
	var grid = null;
	var _mfrId;
	$(function () {
		initcombobox();//初始化融资机构 by gengchunlan 20190606
		var _url = '<%=path%>/rfbase/fncprjeaplysettle/initList.do' ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
  	            
	            { display: '项目名称', name: 'fncPrjNm', align:'center', width: 120 },
	            { display: '项目编号', name: 'fncPrjIdStr',align:'center', width: 200},
	            { display: '创建时间', name: 'crtTm', align:'center', width: 100,render:renderDate},
	            { display: '项目金额', name: 'fncPrjAmt',align:'center', width: 80, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '融资金额', name: 'fncFiAmt', align:'center', width: 100 , render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '支付表数量', name: 'payCnt', align:'center', width: 100 , render: function (rowdata, rowindex, value, column) { 
	            	var h = '';
	    			if(value&&value!="null"){
	    		        h=value;
	    			}else{
	    			    h+="0";
	    			}
	                 return h;
            		},
        	      enabledSort:true}, 
	            { display: '融资经理', name: 'rlNm',align:'center', width: 80 },
	            { display: '提款金额', name: 'transAm',align:'center', width: 100 , render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '租金合计', name: 'totalFa',align:'center', width: 100 , render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
        	    { display: '结清状态', name: 'fncPrjStcd', align:'center', width: 80,render:changeStatus },
	            { display: '操作', width: 200 ,height:'100px', align:'left',
	            	render: function (rowdata, rowindex, value){
	            		//还款表
	            		var repayTBInfo ='<a class="sq-button-hasicon" href="javascript:showReturnPayTB(';
	            		    repayTBInfo +="'"+rowdata.fncPrjId+"'";
	            		    repayTBInfo +=')"><i class="sqBtnIco_4"></i>还款表</a>';
	            		    
            		    //申请提前结清
	            		var eaplySettle ='<a class="sq-button-hasicon" href="javascript:toFncPrjEaplySettlePage(';
	            		    eaplySettle +="'"+rowdata.fncPrjId+"'";
	            		    eaplySettle +=')"><i class="sqBtnIco_4"></i>申请提前结清</a>';
	            	    
            		    //提前结清审核中
	            		var eaplySettling ='<a class="sq-button-hasicon" href="javascript:void(0)"><i class="sqBtnIco_4"></i>结清审核中</a>';
	            	    
	            		//提前结清详情
	            		var detailInfo ='<a class="sq-button-hasicon" href="javascript:toFncPrjEaplySettleDetail(';
	            		    detailInfo +="'"+rowdata.fncPrjId+"'";
	            		    detailInfo +=')"><i class="sqBtnIco_4"></i>结清详情</a>';
	            		
	                    if(rowdata.fncPrjStcd == 7||rowdata.fncPrjStcd == 12){
		                   return repayTBInfo+ " " + eaplySettle;
	            		}
	                    if(rowdata.fncPrjStcd == 9){
	                       return repayTBInfo+ " " + eaplySettling;
	            		}
	            		if(rowdata.fncPrjStcd == 13){
	            		   return repayTBInfo+ " " + detailInfo;
	            		}
	            	}
	            },
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        rownumbers:true,
	        fixedCellHeight:false
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    
	});
	
	//查看还款表
	function showReturnPayTB(_id){
		if(!_id)return;
		Add_navTab('PrdSpl_3'+_id,'还款信息','<%=path%>/rfbase/fncprjpaysch/toRepayModifyPage.do?projid='+_id);
	}
	
	 //提前结清申请
	function toFncPrjEaplySettlePage(_id){
		var prjLgcId=_id;
		 $.ajax({
		   		type: 'GET',
		   		dataType:'json', 
		   		url: '<%=path%>/rfbase/mrgnmanageinfo/getRepayMainStByPrjId.do?prjLgcSn='+prjLgcId,
		   		beforeSend: function(){
		   	       wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		   	     },
		   		success:function(msg){
		   			 wait_dialog.close();
		   			 var e=msg.success;
		   			 if(msg.success == 1){
		   				var fncPrjPaySchMVO=msg.data;
		   				if(fncPrjPaySchMVO.repayStcd!=2){
		   					Add_navTab('PrdSpl_1'+_id,'提前结清申请','<%=path%>/rfbase/fncprjeaplysettle/toPrjEaplySettlePage.do?prjLgcId='+prjLgcId);
						 }else{
							$.ligerDialog.error("该项目正在还款中,无法同时发起提前结清流程！");
						 }
		   			 }else{
		   				 $.ligerDialog.error("无法判断该项目是否正在还款");
		   			 }
		   		}
		     });
	}
	
	 //提前结清申请详情
	function toFncPrjEaplySettleDetail(_id){
		var prjLgcId=_id;
		Add_navTab('PrdSpl_2'+_id,'提前结清详情','<%=path%>/rfbase/fncprjeaplysettle/toPrjEaplySettleInfoListPage.do?prjLgcId='+prjLgcId);
	}
	 
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//改变状态的显示
	function changeStatus(rowdata, index, value){
		if(value==7){
			value="未结清";
		}
		if(value==9){
			value="结清中";
		}
		if(value==13){
			value="已结清";
		}
		return value;
	}
	
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "fncInsId":"",
		    "fncScmId":"",
		    "fncSettleStcd":"",
		    "fncPrjNm":"",
		  });
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}

 //格式化金额
 function moneyChange(value) { 
		var h = '';
			if(value&&value!="null"){
		    h+=fmoney(value, 2);
			}else{
			h+="0.00";
			}
         return h;
		}
 
 //格式化金额
 function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
	//融资机构 start by gengchunlan 20190606
	var frilist = [];
	<c:if test="${not empty frilist}"> frilist = ${frilist}; </c:if>
	 function initcombobox(){
		  var combobox=  $("#fncInsId").ligerComboBox({
	    	     data:frilist,
	             selectBoxWidth: 270,
	             selectBoxHeight: 150,
	             valueField: "id",
	             textField: "fundRasInsNm",
	             autocomplete: function (e){
	                 filter_autoComboboxData(e.key, this);
	                 e.show();
	             }
	          }); 
	 }//end by  gengchunlan 20190606
 
 
</script>


</html>